//
//  ViewController.m
//  NSUserDefault
//
//  Created by 康迂峰 on 14-3-30.
//  Copyright (c) 2014年 康迂峰. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    defause = [NSUserDefaults standardUserDefaults];
    if ([[defause objectForKey:@"color"] isEqualToString:@"green"]) {
        self.view.backgroundColor = [UIColor greenColor];
    }else if ([[defause objectForKey:@"color"] isEqualToString:@"yellow"]) {
        self.view.backgroundColor = [UIColor yellowColor];
    }else if([[defause objectForKey:@"color"] isEqualToString:@"blue"]){
        self.view.backgroundColor = [UIColor blueColor];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)greenButton:(id)sender {
    [NSUserDefaults standardUserDefaults];
    [defause setObject:@"green" forKey:@"color"];
    [defause synchronize];
    self.view.backgroundColor = [UIColor greenColor];
}

- (IBAction)yellowButton:(id)sender {
    [NSUserDefaults standardUserDefaults];
    [defause setObject:@"yellow" forKey:@"color"];
    [defause synchronize];
    self.view.backgroundColor = [UIColor yellowColor];
}

- (IBAction)blueButton:(id)sender {
    [NSUserDefaults standardUserDefaults];
    [defause setObject:@"blue" forKey:@"color"];
    [defause synchronize];
    self.view.backgroundColor = [UIColor blueColor];
}
@end
